<template>
    <div style="width: 40%;margin-left: auto;margin-right: auto">
      <h2 style="color: grey">密码修改</h2><br>
      <el-form :model="form" status-icon  label-width="100px" class="demo-ruleForm" >
        <el-form-item label="原密码:" prop="user_acount" >
          <el-input v-model="form.useroldpassword" placeholder="请输入旧密码"  type="password" style="width:95%"></el-input>
        </el-form-item>
        <el-form-item label="新密码:" prop="user_password">
          <el-input v-model="form.usernewpassword" placeholder="请输入新密码" type="password" style="width:95%" oncopy="return false" onpaste="return false" oncut="return false" oncontextmenu="return false"></el-input>
        </el-form-item>
        <el-form-item label="确认新密码:" prop="user_password">
          <el-input v-model="form.usersurepassword" placeholder="请确认新密码" type="password" style="width:95%" oncopy="return false" onpaste="return false" oncut="return false" oncontextmenu="return false"></el-input>
        </el-form-item>
      </el-form>
      <el-button type="success" v-on:click="manaupdatepwd" plain>确认修改</el-button>
    </div>
</template>

<style>
    body {
        background-color: #fff;
    }
</style>

<script>
    export default {
      name:'updatepwd',
        data() {
            return {
              form:{
                useroldpassword:'',
                usernewpassword:'',
                usersurepassword:''
              }
            }
        },
      methods:{
        manaupdatepwd:function () {

          if(this.form.useroldpassword==""||this.form.useroldpassword==undefined){
            alert("旧密码不能为空!");
            return false;
          }

          if(this.form.usernewpassword==""||this.form.usernewpassword==undefined){
            alert("新密码不能为空!");
            return false;
          }
          if(this.form.usersurepassword==""||this.form.usersurepassword==undefined){
            alert("请确认密码!");
            return false;
          }
          if(this.form.usernewpassword!=this.form.usersurepassword){
            alert("两次密码不一致!");
            return false;
          }
          this.$axios({
            url: `/api/user/manaupdatepwd/` + "?u_newpwd=" + this.form.usernewpassword,
            method: 'get',
          }).then(teaInfoByCode => {  // 请求成功
            if(teaInfoByCode.data=="已修改"){
              alert("修改成功!");
              location.reload();
            }else{
              alert("修改失败!");
              location.reload();
            }
          }).catch(error => {  // 请求失败

          });

        }
      },
    }
</script>
